package com.bdqn.service.impl;

import com.bdqn.mapper.SysUserMapper;
import com.bdqn.pojo.SysRole;
import com.bdqn.pojo.SysUser;
import com.bdqn.service.SysUserService;
import com.bdqn.util.Page;
import com.bdqn.util.PageSupport;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {
    @Resource
    private SysUserMapper sysUserMapper;


    @Override
    public boolean add(SysUser sysUser) {
        sysUserMapper.add(sysUser);
        return true;
    }

    @Override
    public Long count(String realName, Long roleId) {
        return sysUserMapper.count(realName,roleId);
    }

    @Override
    public List<SysUser> page(String realName, Long roleId, PageSupport page) {
        Long pageSize =  page.getPageSize();
        Long pageIndex =  ((page.getCurrentPageNo()-1)*pageSize);
        return sysUserMapper.page(realName,roleId,pageIndex,pageSize);
    }

    @Override
    public SysUser login(String account, String password) {
        if (account == null || password == null) {
            return null;
        }
        return sysUserMapper.getByAccountAndPassword(account,password);
    }

    @Override
    public boolean userExist(String account) {
        if (account == null) {
            return false;
        }
        return sysUserMapper.exist(account)==1;
    }

    @Override
    public SysUser getById(Long userid) {
           if (userid == null) {
               return null;
           }
        return sysUserMapper.getById(userid);
    }

    @Override
    public boolean del(Long userid) {
        if (userid == null) {
            return false;
        }
        sysUserMapper.del(userid);
        return true;
    }
}
